﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS
{
    public partial class Article : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                int articleID = int.Parse(Request.QueryString["ID"]);
                if (!IsPostBack)
                {
                    rptArticleDetailDataSource(articleID);
                    cmsArticleDO objArticle = new cmsArticleBL().Select(new cmsArticleDO() { ArticleID = articleID });

                    //SEO
                    if (!string.IsNullOrEmpty(objArticle.MetaTag))
                    {
                        HtmlMeta metaKey = new HtmlMeta();
                        metaKey.Name = "keywords";
                        metaKey.Content = objArticle.MetaTag;
                        Page.Header.Controls.Add(metaKey);
                    }
                    else
                    { }
                    HtmlMeta metaDesc = new HtmlMeta();
                    metaDesc.Name = "description";
                    if (!string.IsNullOrEmpty(objArticle.MetaDes))
                    {
                        metaDesc.Content = objArticle.MetaDes;
                    }
                    else
                    {
                        metaDesc.Content = objArticle.Description;
                    }
                    Page.Header.Controls.Add(metaDesc);

                    if (!string.IsNullOrEmpty(objArticle.PageTitle))
                    {
                        Page.Title = objArticle.PageTitle + " | " + Ultility.WebTitle();
                    }
                    else
                    {
                        Page.Title = objArticle.Title + " | " + Ultility.WebTitle();
                    }
                    rptOther.DataSource = new DataView(new cmsArticleBL().SelectByCatNum(objArticle.CategoryID, 10), "ArticleID<>" + objArticle.ArticleID.ToString(), "", DataViewRowState.CurrentRows);
                    rptOther.DataBind();
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
        private void rptArticleDetailDataSource(int articleID)
        {
            rptArticleDetail.DataSource = new cmsArticleBL().SelectByPK(articleID);
            rptArticleDetail.DataBind();
        }
        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
    }
}